package com.khoayang.littlefighterchaos.game;

import org.cocos2d.layers.CCLayer;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCParallaxNode;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.types.CGSize;

public class BackgoundGame extends CCLayer {

	public static String ground1= "";
	public static String ground2 ="";
	public static String ground3 ="";
	public static String sky ="";
	public BackgoundGame() {
		CCParallaxNode para = CCParallaxNode.node();
		
		CGSize winSize = CCDirector.sharedDirector().winSize();

//		 ground1 = "background-game/ground2.png";
//		 ground2 = "background-game/ground2.png";
//		 ground3 = "background-game/ground2.png";
//		
//		 sky = "background-game/sky2.bmp";
		
		makeGround(para, winSize, ground1, 0);
		makeGround(para, winSize, ground2, 1);
		makeGround(para, winSize, ground3, 2);
		
		CCSprite spMap1 = CCSprite.sprite(sky);
		spMap1.setScaleX((winSize.width) * 2/ spMap1.getContentSize().width);
		spMap1.setScaleY(winSize.height / spMap1.getContentSize().height / 2);
		para.addChild(spMap1, 1, 0.5f, 1f, spMap1.getContentSize().getWidth()
				/ 2 * spMap1.getScaleX(), winSize.height
				- spMap1.getContentSize().getHeight() / 2 * spMap1.getScaleY());

		addChild(para, 0, 0);
	}

	public void makeGround(CCParallaxNode para, CGSize winSize, String ground, int indexGround) {
		CCSprite mapA = CCSprite.sprite(ground);
		mapA.setScaleX((winSize.width)  / mapA.getContentSize().width);
		mapA.setScaleY(winSize.height * 3 / mapA.getContentSize().height / 4);		
		para.addChild(mapA, 2, 1f, 1f, mapA.getContentSize().getWidth() / 2
				* mapA.getScaleX() + winSize.width*indexGround, mapA.getContentSize().getHeight() / 2
				* mapA.getScaleY());
	}

	public void ChangePosition(float x, float y) {
		this.setPosition(this.getPosition().x - x,
				this.getPosition().y - y);
	}
}
